//
//  CustomOrderShortTableViewCell.m
//  ChunLaiZhuangClient
//
//  Created by zzs on 16/4/16.
//  Copyright © 2016年 CLZ. All rights reserved.
//

#import "CustomOrderShortTableViewCell.h"

@implementation CustomOrderShortTableViewCell

+ (instancetype)cellWithTableView:(UITableView *)tableView{
    static NSString *identifier = @"CustomOrderShortTableViewCell";
    // 1.缓存中取
    CustomOrderShortTableViewCell*cell = [tableView dequeueReusableCellWithIdentifier:identifier];
    // 2.创建
    if (cell == nil) {
        cell = [[CustomOrderShortTableViewCell alloc]initWithStyle:UITableViewCellStyleDefault reuseIdentifier:identifier];
        cell.selectionStyle=UITableViewCellSelectionStyleNone;
    }
    return cell;
}
-(id)initWithStyle:(UITableViewCellStyle)style reuseIdentifier:(NSString *)reuseIdentifier{
    self = [super initWithStyle:style reuseIdentifier:reuseIdentifier];
    if (self) {
        self.contentView.backgroundColor=[UIColor colorWithHexString:@"efeff4"];
        _bgView=[[UIView alloc] initWithFrame:CGRectMake(0,0,SCREEN_WIDTH,100)];
        _bgView.backgroundColor=[UIColor whiteColor];
        _timeLabel=[[UILabel alloc] initWithFrame:CGRectMake(19, 8, 140, 30)];
        _timeLabel.font=[UIFont systemFontOfSize:14];
        _timeLabel.textAlignment=NSTextAlignmentLeft;
        _timeLabel.textColor=[UIColor colorWithHexString:@"000000"];
        [_bgView addSubview:_timeLabel];
        _payStatus=[[UILabel alloc] initWithFrame:CGRectMake(19, 8,SCREEN_WIDTH-140-30, 30)];
        _payStatus.numberOfLines=2;
        _payStatus.minimumFontSize=0.5;
        _payStatus.right=SCREEN_WIDTH-17;
        _payStatus.font=[UIFont systemFontOfSize:15];
        _payStatus.textAlignment=NSTextAlignmentRight;
        _payStatus.textColor=[UIColor colorWithHexString:@"f35959"];
        [_bgView addSubview:_payStatus];
        UIView *lineView=[[UIView alloc] initWithFrame:CGRectMake(15, 40, SCREEN_WIDTH-15, 0.5)];
        lineView.backgroundColor=[UIColor colorWithHexString:@"f1f1f1"];
        [_bgView addSubview:lineView];
        _lineView1=[[UIView alloc] initWithFrame:CGRectMake(15, 40, SCREEN_WIDTH-15, 0.5)];
        _lineView1.backgroundColor=[UIColor colorWithHexString:@"f1f1f1"];
        [_bgView addSubview:_lineView1];
        _bgScrollView=[[UIScrollView alloc] initWithFrame:CGRectMake(0,_lineView1.bottom, SCREEN_WIDTH, 60)];
        [_bgView addSubview:_bgScrollView];
        //商品个数
        _countLabel=[[UILabel alloc] initWithFrame:CGRectMake(19,_lineView1.bottom+10, 150, 25)];
        _countLabel.font=[UIFont systemFontOfSize:12];
        _countLabel.textAlignment=NSTextAlignmentLeft;
        _countLabel.textColor=[UIColor colorWithHexString:@"000000"];
        [_bgView addSubview:_countLabel];
        
        //总金额
        _amountLabel=[[UILabel alloc] initWithFrame:CGRectMake(19, _lineView1.bottom+10, 200, 25)];
        _amountLabel.right=SCREEN_WIDTH-17;
        _amountLabel.font=[UIFont boldSystemFontOfSize:12];
        _amountLabel.textAlignment=NSTextAlignmentRight;
        _amountLabel.textColor=[UIColor colorWithHexString:@"f35959"];
        [_bgView addSubview:_amountLabel];
        [self addSubview:_bgView];
        
        
        
        
    }
    return self;
}


-(void)setFrameModel:(OrderCellFrameModel *)frameModel{
    _bgView.height=150-5;
    _lineView1.bottom=40+frameModel.imageHight;
    _amountLabel.top=_lineView1.bottom+10;
    _countLabel.top=_lineView1.bottom+10;
    _cancleBt.top=_amountLabel.bottom+15;
    _payBt.top=_amountLabel.bottom+15;
    _bgScrollView.top=40;
    if (!self.buttonsArray) {
        self.buttonsArray=[[NSMutableArray alloc] init];
    }else{
        if (self.buttonsArray.count>0) {
            for(UIButton *bt in self.buttonsArray){
                [bt removeFromSuperview];
            }
        }
    }
    
    _frameModel=frameModel;
    
    float edge=19.0;
    float widh=(SCREEN_WIDTH-38-30)/6;
    float distance=6;
    for (int i=0; i<frameModel.dataModel.pictureArray.count; i++) {
        _bgScrollView.contentSize=CGSizeMake(edge*2+widh*frameModel.dataModel.pictureArray.count+distance*(frameModel.dataModel.pictureArray.count-1), 60);
        AccountOrdersProductListModel *productModel=frameModel.dataModel.pictureArray[i];
        UIButton *imageBt=[UIButton buttonWithType:UIButtonTypeCustom];
        imageBt.frame=CGRectMake(0, 0, widh,widh);
        [imageBt sd_setImageWithURL:[NSURL URLWithString:productModel.image] forState:UIControlStateNormal placeholderImage:nil];
        imageBt.left=edge+(widh+distance)*i;
        imageBt.top=5;
        imageBt.tag=i;
        [_bgScrollView addSubview:imageBt];
        imageBt.layer.borderColor=[UIColor colorWithHexString:@"f1f1f1"].CGColor;
        imageBt.clipsToBounds=YES;
        imageBt.layer.borderWidth=0.5;
        [self.buttonsArray addObject:imageBt];
    }
    self.timeLabel.text=frameModel.dataModel.date_added;
    self.countLabel.text=[NSString stringWithFormat:@"共%@件商品",frameModel.dataModel.product_total];
    self.payStatus.text=frameModel.dataModel.status;
    _amountLabel.text=[NSString stringWithFormat:@"总金额: %@",frameModel.dataModel.total];
    //2、您的订单已经打包完成 3、包裹已经发出 7、已取消  5、已完成  1、订单已经开始配货    15、收到订单
    if ([frameModel.dataModel.status_id intValue]==5||[frameModel.dataModel.status_id intValue]==7){
        self.payStatus.textColor=[UIColor colorWithHexString:@"bebebe"];
        _amountLabel.textColor=[UIColor blackColor];
    }else {
        _payStatus.textColor=[UIColor colorWithHexString:@"f35959"];
        _amountLabel.textColor=[UIColor colorWithHexString:@"f35959"];
    }
}
- (void)setSelected:(BOOL)selected animated:(BOOL)animated {
    [super setSelected:selected animated:animated];
    
    // Configure the view for the selected state
}



@end
